import { createSlice } from '@reduxjs/toolkit';

const settingSlice = createSlice({
	name: 'setting',
	initialState: {
		language: 'zh', // 0: zh | 1: zh-TW |  系统语言
		background: {
			type: 'none', // none | blur | custom | image
			image: '',
			blurRadius: 12,
			selectIndex: 0,
			isUploadImage: false,
			api: '',
			value: '',
			apiClear: 'BackgroundTexture.clear'
		}, // 虚拟背景
		watermark: {
			position: 1,
			image: '',
			selectIndex: 0,
			type: 'none'
		}, // 水印
		backgroundVisible: false, // 背景设置界面
		languageVisible: false // 语言设置界面
	},

	reducers: {
		setBackground(state, action) {
			let background: any = action.payload;
			return { ...state, background };
		},

		setWatermark(state, action) {
			let watermark: any = action.payload;
			return { ...state, watermark };
		},

		setLanguage(state, action) {
			let language: any = action.payload;
			return { ...state, language };
		},

		setBackgroundVisible(state, action) {
			let backgroundVisible: any = action.payload;
			return { ...state, backgroundVisible };
		},

		setLanguageVisible(state, action) {
			let languageVisible: any = action.payload;
			return { ...state, languageVisible };
		},

		clearSettingData() {
			return {
				language: 'zh',
				background: {
					type: 'none', // none | blur | custom | image
					image: '',
					blurRadius: 12,
					selectIndex: 0,
					isUploadImage: false,
					api: '',
					value: '',
					apiClear: 'BackgroundTexture.clear'
				}, // 虚拟背景
				watermark: {
					position: 1,
					image: '',
					selectIndex: 0,
					type: 'none'
				}, // 水印
				backgroundVisible: false,
				languageVisible: false
			};
		}
	}
});

export const { setBackground, setWatermark, setLanguage, clearSettingData, setBackgroundVisible, setLanguageVisible } = settingSlice.actions;
export default settingSlice.reducer;
